//
//  NSString+LHLSHA_1.m
//  UI_24_加密
//
//  Created by 李昊林 on 16/8/16.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "NSString+LHLSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (LHLSHA_1)
- (NSString *)stringWithSHA_1 {
    //1.将字符串转成C语言字符串
    const char *cString = [self UTF8String];
    //2.求长度
    CC_LONG len = (CC_LONG)strlen(cString);
    unsigned char bytes[CC_SHA1_DIGEST_LENGTH];
    CC_SHA1(cString, len, bytes);
    //3.SHA1转换
    NSMutableString *finalSHA1 = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
    for (int i = 0 ; i <CC_SHA1_DIGEST_LENGTH; i++) {
        [finalSHA1 appendFormat:@"%02x",bytes[i]];
    }
    return @"";
}

@end
